Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add classification functions #11792

Closed

Conversation

yuandagits
Copy link
Contributor

Summary:
Add the classification functions from presto into velox: https://prestodb.io/docs/current/functions/aggregate.html#classification-metrics-aggregate-functions

Classification functions all use FixedDoubleHistogram, which is a data structure to represent the bucket of weights. The index of the bucket for the histogram is evenly distributed between the min and value values.

For all of the classification functions, the only difference is the extraction phase. All other steps will be the same.

At a high level:

  • addRawInput will add a value into either the true or false weight bucket. The bucket to add the value to will depend on the prediction value. The prediction value is linearly mapped into a bucket based on (min, max and bucketCount) by normalizing the prediction between min and max.

  • The schema of the intermediate states is [version header][bucket count][min][max][weights]

Differential Revision: D66684198

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 9, 2024
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66684198

Copy link

netlify bot commented Dec 9, 2024

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit 63d36d6
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/675e07b93ea53a0008b7a8c1

yuandagits added a commit to yuandagits/velox that referenced this pull request Dec 9, 2024
Summary:

Add the classification functions from presto into velox: https://prestodb.io/docs/current/functions/aggregate.html#classification-metrics-aggregate-functions

Classification functions all use `FixedDoubleHistogram`, which is a data structure to represent the bucket of weights. The index of the bucket for the histogram is evenly distributed between the min and value values. 

For all of the classification functions, the only difference is the extraction phase. All other steps will be the same.

At a high level:
- addRawInput will add a value into either the true or false weight bucket. The bucket to add the value to will depend on the prediction value. The prediction value is linearly mapped into a bucket based on (min, max and bucketCount) by normalizing the prediction between min and max.

- The schema of the intermediate states is [version header][bucket count][min][max][weights]

Differential Revision: D66684198
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66684198

@yuandagits yuandagits changed the title feat: add classification functions feat: Add classification functions Dec 9, 2024
@yuandagits yuandagits requested review from Yuhta and xiaoxmeng December 9, 2024 05:20
in.copyTo(&min, 1);
in.copyTo(&max, 1);

auto ret = FixedDoubleHistogram(bucketCount, min, max, allocator);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid memory allocation for the buckets? Just merge with a view on the deserialized bytes (be careful about the alignment though).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhhh good idea

/// std::vector<double>::max_size(), which may be less than 2^63 depending. To
/// account for this, we have two buckets which may be used to store the
/// weights with each bucket being at most kMaxBucketCount in size.
static constexpr int64_t kMaxBucketCount =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice max_size is at least 2^60 on 64 bits system, I don't think any system can give that large contiguous memory in one go. So you don't need to split the weights into 2 arrays for the discrepancy between 2^60 vs 2^64 (you can put a VELOX_CHECK_LT(bucketCount, weights_.max_size()) in validateParameters if you are really concerned about this).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I added this because it was something the fuzzer caught

yuandagits added a commit to yuandagits/velox that referenced this pull request Dec 11, 2024
Summary:

Add the classification functions from presto into velox: https://prestodb.io/docs/current/functions/aggregate.html#classification-metrics-aggregate-functions

Classification functions all use `FixedDoubleHistogram`, which is a data structure to represent the bucket of weights. The index of the bucket for the histogram is evenly distributed between the min and value values.

For all of the classification functions, the only difference is the extraction phase. All other steps will be the same.

At a high level:
- addRawInput will add a value into either the true or false weight bucket. The bucket to add the value to will depend on the prediction value. The prediction value is linearly mapped into a bucket based on (min, max and bucketCount) by normalizing the prediction between min and max.

- The schema of the intermediate states is [version header][bucket count][min][max][weights]

Differential Revision: D66684198
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66684198

yuandagits added a commit to yuandagits/velox that referenced this pull request Dec 11, 2024
Summary:

Add the classification functions from presto into velox: https://prestodb.io/docs/current/functions/aggregate.html#classification-metrics-aggregate-functions

Classification functions all use `FixedDoubleHistogram`, which is a data structure to represent the bucket of weights. The index of the bucket for the histogram is evenly distributed between the min and value values.

For all of the classification functions, the only difference is the extraction phase. All other steps will be the same.

At a high level:
- addRawInput will add a value into either the true or false weight bucket. The bucket to add the value to will depend on the prediction value. The prediction value is linearly mapped into a bucket based on (min, max and bucketCount) by normalizing the prediction between min and max.

- The schema of the intermediate states is [version header][bucket count][min][max][weights]

Differential Revision: D66684198
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66684198

yuandagits added a commit to yuandagits/velox that referenced this pull request Dec 13, 2024
Summary:

Add the classification functions from presto into velox: https://prestodb.io/docs/current/functions/aggregate.html#classification-metrics-aggregate-functions

Classification functions all use `FixedDoubleHistogram`, which is a data structure to represent the bucket of weights. The index of the bucket for the histogram is evenly distributed between the min and value values.

For all of the classification functions, the only difference is the extraction phase. All other steps will be the same.

At a high level:
- addRawInput will add a value into either the true or false weight bucket. The bucket to add the value to will depend on the prediction value. The prediction value is linearly mapped into a bucket based on (min, max and bucketCount) by normalizing the prediction between min and max.

- The schema of the intermediate states is [version header][bucket count][min][max][weights]

Differential Revision: D66684198
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66684198

@yuandagits yuandagits requested a review from Yuhta December 13, 2024 16:11
yuandagits added a commit to yuandagits/velox that referenced this pull request Dec 14, 2024
Summary:

Add the classification functions from presto into velox: https://prestodb.io/docs/current/functions/aggregate.html#classification-metrics-aggregate-functions

Classification functions all use `FixedDoubleHistogram`, which is a data structure to represent the bucket of weights. The index of the bucket for the histogram is evenly distributed between the min and value values.

For all of the classification functions, the only difference is the extraction phase. All other steps will be the same.

At a high level:
- addRawInput will add a value into either the true or false weight bucket. The bucket to add the value to will depend on the prediction value. The prediction value is linearly mapped into a bucket based on (min, max and bucketCount) by normalizing the prediction between min and max.

- The schema of the intermediate states is [version header][bucket count][min][max][weights]

Reviewed By: Yuhta

Differential Revision: D66684198
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66684198

yuandagits added a commit to yuandagits/velox that referenced this pull request Dec 14, 2024
Summary:

Add the classification functions from presto into velox: https://prestodb.io/docs/current/functions/aggregate.html#classification-metrics-aggregate-functions

Classification functions all use `FixedDoubleHistogram`, which is a data structure to represent the bucket of weights. The index of the bucket for the histogram is evenly distributed between the min and value values.

For all of the classification functions, the only difference is the extraction phase. All other steps will be the same.

At a high level:
- addRawInput will add a value into either the true or false weight bucket. The bucket to add the value to will depend on the prediction value. The prediction value is linearly mapped into a bucket based on (min, max and bucketCount) by normalizing the prediction between min and max.

- The schema of the intermediate states is [version header][bucket count][min][max][weights]

Reviewed By: Yuhta

Differential Revision: D66684198
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66684198

Summary:

Add the classification functions from presto into velox: https://prestodb.io/docs/current/functions/aggregate.html#classification-metrics-aggregate-functions

Classification functions all use `FixedDoubleHistogram`, which is a data structure to represent the bucket of weights. The index of the bucket for the histogram is evenly distributed between the min and value values.

For all of the classification functions, the only difference is the extraction phase. All other steps will be the same.

At a high level:
- addRawInput will add a value into either the true or false weight bucket. The bucket to add the value to will depend on the prediction value. The prediction value is linearly mapped into a bucket based on (min, max and bucketCount) by normalizing the prediction between min and max.

- The schema of the intermediate states is [version header][bucket count][min][max][weights]

Reviewed By: Yuhta

Differential Revision: D66684198
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66684198

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 12942c1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants